import { LockOutlined, UserOutlined } from '@ant-design/icons';
import { Button, Checkbox, Form, Input,message } from 'antd';
import React from 'react';
import { history } from 'umi';

import "./rightCol.css"

// eslint-disable-next-line react/prefer-stateless-function
class RightCol extends React.Component{
  // eslint-disable-next-line no-useless-constructor
  constructor(props) {
    super(props);
  }

  render() {
    return(<>
      RightCol</>)
  }
}
const App = () => {
  const onFinish = (values) => {
    // eslint-disable-next-line no-console
    console.log('Received values of form: ', values);
    let url2="http://1.94.134.166:8805/login?";
    url2 = url2+"username="+String(values.username);
    url2 = url2+"&password="+String(values.password);
    console.log(url2);
    //const url="http://1.94.134.166:8805/login?username=admin&password=123456";
    fetch(url2,{method:'POST'})
      .then((response)=>response.json())
      .then((res)=>{
        const {code=0,msg="",data={}}=res;
        console.log(res);
        if (code) {
          message.error(msg);
          return;
        }
        const {token=""}=data;
        localStorage.setItem('Authorization', 'Bearer '+ token);
        message.success(msg);
        history.push('/Demo2');
      })
  };
  return (
    <>
      <div id="login_title">XXXX管理系统</div>
      <div id="login_content">
        <Form
          name="normal_login"
          className="login-form"
          initialValues={{
            username: "admin",
            password: "123456",
            remember: true,
          }}
          onFinish={onFinish}

        >
          <Form.Item
            name="username"
            rules={[
              {
                required: true,
                message: 'Please input your Username!',
              },
            ]}
          >
            <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="Username" />
          </Form.Item>
          <Form.Item
            name="password"
            rules={[
              {
                required: true,
                message: 'Please input your Password!',
              },
            ]}
          >
            <Input
              prefix={<LockOutlined className="site-form-item-icon" />}
              type="password"
              placeholder="Password"
            />
          </Form.Item>
          <Form.Item>
            <Form.Item name="remember" valuePropName="checked" noStyle>
              <Checkbox>记住</Checkbox>
            </Form.Item>

            <a className="login-form-forgot" href="">
              忘记密码
            </a>
          </Form.Item>

          <Form.Item>
            <Button type="primary" htmlType="submit" className="login-form-button">
              登录
            </Button>
            Or <a href="">注册</a>
          </Form.Item>
        </Form>
      </div>

    </>
  );
};
export default App;
